package com.eqdd.yiqidian.ui.gongneng.kehu.fragment;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import com.eqdd.yiqidian.JihuiFragmentCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.recycleadapter.BaseQuickAdapter;
import com.eqdd.yiqidian.adapter.recycleadapter.BaseViewHolder;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.base.BaseFragment;
import com.eqdd.yiqidian.bean.JihuiBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lvzhihao on 17-5-24.
 */

public class JjhuiFragment extends BaseFragment {
    JihuiFragmentCustom dataBinding;
    private BaseQuickAdapter<JihuiBean, BaseViewHolder> quickAdapter;
    private List<JihuiBean> jihuiBeans;

    @Override
    protected void setView() {

        if (quickAdapter == null) {
            dataBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
            quickAdapter = new BaseQuickAdapter<JihuiBean, BaseViewHolder>(R.layout.list_item_13, new ArrayList<>()) {

                @Override
                protected void convert(BaseViewHolder helper, JihuiBean item) {

                    helper.setText(R.id.tv_left_center_content,item.getName())
                            .setText(R.id.tv_upper_right_content,item.getTime())
                            .setText(R.id.tv_down_right_content,item.getTel());
                }
            };
            dataBinding.recyclerView.setAdapter(quickAdapter);
            if (jihuiBeans != null) {
                ArrayList<JihuiBean> temp = new ArrayList<>();
                temp.addAll(jihuiBeans);
                quickAdapter.notifyDataChanged(temp, true);
                ItemClickSupport.addTo(dataBinding.recyclerView)
                        .setOnItemClickListener((rv, position, v) -> {

                        });
            }
        }
    }

    @Override
    protected void initData() {

        jihuiBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            JihuiBean jihuiBean = new JihuiBean();
            jihuiBean.setName("jihuinname" + i);
            jihuiBean.setTime("jihuitime" + i);
            jihuiBean.setTel("jihuitel" + i);
            jihuiBeans.add(jihuiBean);
        }
        if (quickAdapter != null) {
            ArrayList<JihuiBean> temp = new ArrayList<>();
            temp.addAll(jihuiBeans);
            quickAdapter.notifyDataChanged(temp, true);
        }
    }

    @Override
    public ViewDataBinding initBinding(LayoutInflater inflater) {
        return dataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_jihui, null, false);
    }

    @Override
    public void onClick(View v) {

    }
}
